home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ für Kids
/
C++ for kids.iso
/
SETUP
/
US
/
CBUILDER
/
DATA.Z
/
IOSTREAM.H
< prev
next >
Wrap
C/C++ Source or Header
|
1997-02-13
|
36KB
|
872 lines
/* iostream.h -- basic stream I/O declarations
There are some inline functions here which generate a LOT of code
(as much as 300 bytes), but are available inline because AT&T did
it that way. We have also made them true functions in the library
and conditionally deleted the inline code from this header.
If you really want these big functions to be inline, #define the
macro name _BIG_INLINE_ before including this header.
Programs will compile and link correctly even if some modules are
compiled with _BIG_INLINE_ and some are not.
*/
/*
* C/C++ Run Time Library - Version 8.0
*
* Copyright (c) 1990, 1997 by Borland International
* All Rights Reserved.
*
*/
/* $Revision: 8.6 $ */
#ifndef __cplusplus
#error Must use C++ for the type iostream.
#endif
#ifndef __IOSTREAM_H
#define __IOSTREAM_H
#if !defined(___DEFS_H)
#include <_defs.h>
#endif
#if !defined(__STRING_H)
#include <string.h> // to get strnicmp, memcpy and NULL
#endif
#if !defined(RC_INVOKED)
#pragma pack(push, 1)
#if defined(__BCOPT__)
#if !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
#pragma option -po- // disable Object data calling convention
#endif
#endif
#if !defined(__TINY__)
#pragma option -RT
#endif
#pragma option -Vo- // set standard C++ options
#if defined(__STDC__)
#pragma warn -nak
#endif
#endif /* !RC_INVOKED */
// Definition of EOF must match the one in <stdio.h>
#define EOF (-1)
// extract a char from int i, ensuring that zapeof(EOF) != EOF
#define zapeof(i) ((unsigned char)(i))
typedef long streampos;
typedef long streamoff;
_CLASSDEF(ios)
_CLASSDEF(streambuf)
_CLASSDEF(istream)
_CLASSDEF(ostream)
_CLASSDEF(iostream)
_CLASSDEF(istream_withassign)
_CLASSDEF(ostream_withassign)
_CLASSDEF(iostream_withassign)
class _EXPCLASS ios {
public:
// stream status bits
enum io_state {
goodbit = 0x00, // no bit set: all is ok
eofbit = 0x01, // at end of file
failbit = 0x02, // last I/O operation failed
badbit = 0x04, // invalid operation attempted
hardfail = 0x80 // unrecoverable error
};
// stream operation mode
enum open_mode {
in = 0x01, // open for reading
out = 0x02, // open for writing
ate = 0x04, // seek to eof upon original open
app = 0x08, // append mode: all additions at eof
trunc = 0x10, // truncate file if already exists
nocreate = 0x20, // open fails if file doesn't exist
noreplace= 0x40, // open fails if file already exists
binary = 0x80 // binary (not text) file
};
// stream seek direction
enum seek_dir { beg=0, cur=1, end=2 };
// formatting flags
enum {
skipws = 0x0001, // skip whitespace on input
left = 0x0002, // left-adjust output
right = 0x0004, // right-adjust output
internal = 0x0008, // padding after sign or base indicator
dec = 0x0010, // decimal conversion
oct = 0x0020, // octal conversion
hex = 0x0040, // hexadecimal conversion
showbase = 0x0080, // use base indicator on output
showpoint = 0x0100, // force decimal point (floating output)
uppercase = 0x0200, // upper-case hex output
showpos = 0x0400, // add '+' to positive integers
scientific= 0x0800, // use 1.2345E2 floating notation
fixed = 0x1000, // use 123.45 floating notation
unitbuf = 0x2000, // flush all streams after insertion
stdio = 0x4000, // flush stdout, stderr after insertion
boolalpha = 0x8000 // insert/extract bools as text or numeric
};
// constants for second parameter of seft()
static const long basefield; // dec | oct | hex
static const long adjustfield; // left | right | internal
static const long floatfield; // scientific | fixed
// constructor, destructor
_RTLENTRY ios(streambuf _FAR *);
virtual _RTLENTRY ~ios();
// for reading/setting/clearing format flags
long _RTLENTRY flags();
long _RTLENTRY flags(long);
long _RTLENTRY setf(long _setbits, long _field);
long _RTLENTRY setf(long);
long _RTLENTRY unsetf(long);
// reading/setting field width
int _RTLENTRY width();
int _RTLENTRY width(int);
// reading/setting padding character
char _RTLENTRY fill();
char _RTLENTRY fill(char);
// reading/setting digits of floating precision
int _RTLENTRY precision(int);
int _RTLENTRY precision();
// reading/setting ostream tied to this stream
ostream _FAR * _RTLENTRY tie(ostream _FAR *);
ostream _FAR * _RTLENTRY tie();
// find out about current stream state
int _RTLENTRY rdstate(); // return the stream state
int _RTLENTRY eof(); // non-zero on end of file
int _RTLENTRY fail(); // non-zero if an operation failed
int _RTLENTRY bad(); // non-zero if error occurred
int _RTLENTRY good(); // non-zero if no state bits set
void _RTLENTRY clear(int = 0); // set the stream state
_RTLENTRY operator void _FAR * (); // zero if state failed
int _RTLENTRY operator! (); // non-zero if state failed
streambuf _FAR * _RTLENTRY rdbuf(); // get the assigned streambuf
// for declaring additional flag bits and user words
static long _RTLENTRY bitalloc(); // acquire a new flag bit, value returned
static int _RTLENTRY xalloc(); // acquire a new user word, index returned
long _FAR & _RTLENTRY iword(int); // return the nth user word as an int
void _FAR * _FAR & _RTLENTRY pword(int); // return the nth user word as a pointer
static void _RTLENTRY sync_with_stdio();
// obsolete, for streams 1.2 compatibility
int _RTLENTRY skip(int);
int delbuf() {return x_delbuf;}
int delbuf(int _new) {int _x=x_delbuf;x_delbuf=_new;return _x;}
protected:
// additional state flags for ispecial and ospecial
enum { skipping = 0x100, tied = 0x200 };
streambuf _FAR * bp; // the associated streambuf
ostream _FAR * x_tie; // the tied ostream, if any
int state; // status bits
int ispecial; // istream status bits ***
int ospecial; // ostream status bits ***
long x_flags; // formatting flag bits
int x_precision; // floating-point precision on output
int x_width; // field width on output
int x_fill; // padding character on output
int isfx_special; // unused ***
int osfx_special; // unused ***
int x_delbuf; // unused ***
int assign_private; // unused ***
/*
* The data members marked with *** above are not documented in the AT&T
* release of streams, so we cannot guarantee compatibility with any
* other streams release in the use or values of these data members.
* If you can document any expected behavior of these data members, we
* will try to adjust our implementation accordingly.
*/
_RTLENTRY ios(); // null constructor, does not initialize
void _RTLENTRY init(streambuf _FAR *); // the actual initialization
void _RTLENTRY setstate(int); // set all status bits
static void _RTLENTRY (*stdioflush)();
private:
// for extra flag bits and user words
static long nextbit;
static int usercount;
union ios_user_union _FAR *userwords;
int nwords;
void _RTLENTRY usersize(int);
// these declarations prevent automatic copying of an ios
_RTLENTRY ios(ios _FAR &); // declared but not defined
void _RTLENTRY operator= (ios _FAR &); // declared but not defined
};
inline streambuf _FAR * _RTLENTRY ios::rdbuf() { r